package com.dingxin.ship_together_api.config.rabbitmq;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

import static com.dingxin.ship_together_api.config.rabbitmq.RabbitMQConfig.*;

@Service
public class DelayMessageSender {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMsg(String orderId, DelayTypeEnum type) {
        // 发送其他延迟时长的的消息，需要绑定新的消息队列
        if (type == DelayTypeEnum.DELAY_30m) {
            CompletableFuture.runAsync(() -> {
                rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME, DELAY_QUEUE_ROUTING_KEY, orderId);
            });
        }
    }
}
